package com.liruo.learn.spring.mvc.controller.valid.custom;


import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Author:liruo
 * @Date:2023-06-07-22:30:33
 * @Desc
 */
@Slf4j
public class CustomValidation implements ConstraintValidator<CustomValid, CustomValidBean> {

    @Override
    public void initialize(CustomValid customValid) {
        log.info("message={}",customValid.message());
    }

    @Override
    public boolean isValid(CustomValidBean value, ConstraintValidatorContext context) {
        return StringUtils.hasText(value.getRegxTest()) && value.getRegxTest().startsWith("regxTest");
    }
}
